package com.russell.pms.dao.hibernate;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.russell.pms.dao.Dao;

/**
 * This class serves as the Base class for all other Daos - namely to hold
 * common methods that they might all use. Can be used for standard CRUD
 * operations.
 * 
 * @author <a href="mailto:fvinluan@gmail.com">Francis Vinluan</a>
 * @version $Revision: 1.0 $
 */

public class BaseDaoHibernate implements Dao {
	protected final Logger logger = LoggerFactory.getLogger(getClass());

	private SessionFactory sessionFactory;

	/**
	 * Method getCurrentSession.
	 * 
	 * @return Session
	 */
	protected Session getCurrentSession() {
		Session session = getSessionFactory().getCurrentSession();

		return session;

	}

	/**
	 * Method getSessionFactory.
	 * 
	 * @return SessionFactory
	 */
	public SessionFactory getSessionFactory() {
		return sessionFactory;
	}

	/**
	 * Method setSessionFactory.
	 * 
	 * @param sessionFactory
	 *            SessionFactory
	 */
	public void setSessionFactory(SessionFactory sessionFactory) {
		if (logger.isDebugEnabled()) {
			logger.debug("setSessionFactory begins:");
		}
		this.sessionFactory = sessionFactory;
		if (logger.isDebugEnabled()) {
			logger.debug("setSessionFactory ends:");
		}
	}

}
